***********************************************************************************
***	Replication file for:                                                     	***
*** Braun, S. T. and Stuhler, J. (2024). The Economic Consequences of 			***
***	Being Widowed by War: A Life-Cycle Perspective.	     						***
***																				***
***	Journal of Public Economics                                                 ***
***   							                                                ***
*** Script:		3-mzu-71-regressions.do							   			 	***	
*** Purpose:	Produces regression results, MZU1971							*** 
***																				***
*** Tables:		2, 3, B1, C1													***
***	Figure:		---																***
***********************************************************************************

*** Load data
use "$widowsdir/processed/mzu1971-edit.dta", clear

********************************************************************************
*** Sample restrictions
********************************************************************************

** Keep only females
keep if d_female == 1 

** Keep only observation without missing covariates 
drop if occ_cat10_1939 == . 
drop if d_expellee == . | d_SBZ == .
drop if years_schooling == . | years_education == .


********************************************************************************
*** Generate additional outcome variables
********************************************************************************

* married in 1971
gen d_married_1971 = (marital_status == 2)

* living alone in 1971
gen d_alone_1971 = (no_hh_pers == 1)

* living with non-family member 
gen d_non_family_1971 = (non_family_person == 1)

* Occupational status 1950, 1960, 1971
foreach t in 1950 1960 1971{
	gen d_selfemployed_`t' 		= (occ_cat10_`t' == 2)
	gen d_farmer_`t' 			= (occ_cat10_`t' == 3)
	gen d_civilservant_`t'		= (occ_cat10_`t' == 4)
	gen d_whitecollar_`t'		= (occ_cat10_`t' == 5) 
	gen d_bluecollar_`t'		= (occ_cat10_`t' == 6)
	gen d_apprentices_`t'		= (occ_cat10_`t' == 7)
	gen d_helping_family_`t'	= (occ_cat10_`t' == 8)
}

* Recode 1939 in education and apprenticeship as out-of-labor-force to avoid sparse categorical variable
recode occ_cat10_1939 1 7 9 = 10	



********************************************************************************
***	The following regressions provide the input for the following tables: 
***
*** Table 2: The impact of WWII widowhood on demography, labor market status, 
*** income, and wealth in 1971
***
*** Table 3: The impact of war widowhood on labor market outcomes in 1950-1971 
***
*** Table B1: Robustness: The impact of war widowhood on market work in 
***	1950-1971 across samples
***
*** Note that the do file replicates the results for all outcome variables across
*** all samples, whereas Table B1 presents only the main employment results for 
*** the robustness samples. 
***
*** Results are stored, separately for each sample, in Excel spreadsheets. For 
*** each outcome variable, the results are in a separate sheet. 
********************************************************************************

********************************************************************************
*** Regression results for different samples
********************************************************************************

foreach sample in sample_baseline sample_rob1 sample_rob2 sample_rob3 sample_rob4 { 

preserve 

keep if `sample' == 1

********************************************************************************
*** a) Unconditional (not conditional on market work)
***	   (Table 2, except for parts of Panel C2; Table 3, Panel A; Table B1)
********************************************************************************

*** Dependent variables: 
** Demography: Married in 1971, living with non-family member in 1971, living alone in 1971, # kids in 1971, 
** Wealth/income: Personal income 1971, welfare support as main income 1971, household income 1971, house ownership 1971 
** Labor market status 1950/1960/1971 (Market employment, helping family, unemployed, out of the labor force)
** Occupational status 1950/1960/1971 (self-employed, farmer, civil servant, white collar, blue collar)
foreach y in 	d_married_1971 d_non_family_1971 d_alone_1971 kids_1971  ///
				income_midpoints_level d_welfare_support hh_income_pc d_houseowner_1971 ///
				d_status_1950_cat1 d_status_1950_cat2 d_status_1950_cat3 d_status_1950_cat4 ///
				d_status_1960_cat1 d_status_1960_cat2 d_status_1960_cat3 d_status_1960_cat4 ///
				d_status_1971_cat1 d_status_1971_cat2 d_status_1971_cat3 d_status_1971_cat4 ///
				d_selfemployed_1950 d_farmer_1950 d_civilservant_1950 d_whitecollar_1950 d_bluecollar_1950  ///
				d_selfemployed_1960 d_farmer_1960 d_civilservant_1960 d_whitecollar_1960 d_bluecollar_1960  ///
				d_selfemployed_1971 d_farmer_1971 d_civilservant_1971 d_whitecollar_1971 d_bluecollar_1971  {

* Define locals for names of dependent variable and of excel sheet
if "`y'" == "d_married_1971"{
local depvar `"Married in 1971 (0/1)"'
local sheetname  `"married1971"'
}

if "`y'" == "d_non_family_1971"{
local depvar `"Living with non-family member (0/1)"'
local sheetname  `"nonfam1971"'
}

if "`y'" == "d_alone_1971"{
local depvar `"Living alone in 1971 (0/1)"'
local sheetname  `"alone1971"'
}

if "`y'" == "kids_1971"{
local depvar `"Number of kids in 1971 (level)"'
local sheetname  `"kids1971"'
}



if "`y'" == "income_midpoints_level"{
local depvar `"Income interval midpoints in 1971 (level)"'
local sheetname  `"midinc1971level"'
}

if "`y'" == "d_welfare_support"{
local depvar `"Welfare support as main income source 1971 (0/1)"'
local sheetname  `"welfare1971"'
}

if "`y'" == "hh_income_pc"{
local depvar `"Household income per capita (level)"'
local sheetname  `"hhincpc"'
}

if "`y'" == "d_houseowner_1971"{
local depvar `"House ownership 1971 (0/1)"'
local sheetname  `"house1971"'
}



if "`y'" == "d_status_1950_cat1"{
local depvar `"Market employment 1950 (0/1)"'
local sheetname  `"marempl1950"'
}

if "`y'" == "d_status_1960_cat1"{
local depvar `"Market employment 1960 (0/1)"'
local sheetname  `"marempl1960"'
}

if "`y'" == "d_status_1971_cat1"{
local depvar `"Market employment 1971 (0/1)"'
local sheetname  `"marempl1971"'
}

if "`y'" == "d_status_1950_cat2"{
local depvar `"Working family member 1950 (0/1)"'
local sheetname  `"wfam1950"'
}

if "`y'" == "d_status_1960_cat2"{
local depvar `"Working family member 1960 (0/1)"'
local sheetname  `"wfam1960"'
}

if "`y'" == "d_status_1971_cat2"{
local depvar `"Working family member 1971 (0/1)"'
local sheetname  `"wfam1971"'
}

if "`y'" == "d_status_1950_cat3"{
local depvar `"Unemployed 1950 (0/1)"'
local sheetname  `"unem1950"'
}

if "`y'" == "d_status_1960_cat3"{
local depvar `"Unemployed 1960 (0/1)"'
local sheetname  `"unem1960"'
}

if "`y'" == "d_status_1971_cat3"{
local depvar `"Unemployed 1971 (0/1)"'
local sheetname  `"unem1971"'
}

if "`y'" == "d_status_1950_cat4"{
local depvar `"Out of labor force 1950 (0/1)"'
local sheetname  `"outlf1950"'
}

if "`y'" == "d_status_1960_cat4"{
local depvar `"Out of labor force 1960 (0/1)"'
local sheetname  `"outlf1960"'
}

if "`y'" == "d_status_1971_cat4"{
local depvar `"Out of labor force 1971 (0/1)"'
local sheetname  `"outlf1971"'
}



if "`y'" == "d_selfemployed_1950"{
local depvar `"Self employed 1950 (0/1)"'
local sheetname  `"selfemp1950"'
}

if "`y'" == "d_farmer_1950"{
local depvar `"Farmer 1950 (0/1)"'
local sheetname  `"farmer1950"'
}

if "`y'" == "d_civilservant_1950"{
local depvar `"Civil servant 1950 (0/1)"'
local sheetname  `"civilserv1950"'
}

if "`y'" == "d_whitecollar_1950"{
local depvar `"White collar 1950 (0/1)"'
local sheetname  `"whitecol1950"'
}

if "`y'" == "d_bluecollar_1950"{
local depvar `"Blue collar 1950 (0/1)"'
local sheetname  `"bluecol1950"'
}

if "`y'" == "d_selfemployed_1960"{
local depvar `"Self employed 1960 (0/1)"'
local sheetname  `"selfemp1960"'
}

if "`y'" == "d_farmer_1960"{
local depvar `"Farmer 1960 (0/1)"'
local sheetname  `"farmer1960"'
}

if "`y'" == "d_civilservant_1960"{
local depvar `"Civil servant 1960 (0/1)"'
local sheetname  `"civilserv1960"'
}

if "`y'" == "d_whitecollar_1960"{
local depvar `"White collar 1960 (0/1)"'
local sheetname  `"whitecol1960"'
}

if "`y'" == "d_bluecollar_1960"{
local depvar `"Blue collar 1960 (0/1)"'
local sheetname  `"bluecol1960"'
}

if "`y'" == "d_selfemployed_1971"{
local depvar `"Self employed 1971 (0/1)"'
local sheetname  `"selfemp1971"'
}

if "`y'" == "d_farmer_1971"{
local depvar `"Farmer 1971 (0/1)"'
local sheetname  `"farmer1971"'
}

if "`y'" == "d_civilservant_1971"{
local depvar `"Civil servant 1971 (0/1)"'
local sheetname  `"civilserv1971"'
}

if "`y'" == "d_whitecollar_1971"{
local depvar `"White collar 1971 (0/1)"'
local sheetname  `"whitecol1971"'
}

if "`y'" == "d_bluecollar_1971"{
local depvar `"Blue collar 1971 (0/1)"'
local sheetname  `"bluecol1971"'
}

putexcel set "$widowsdir/results/tables/reg_`sample'.xlsx", modify sheet(`sheetname')
putexcel B1 = "Dep: `depvar'"
putexcel A2 = "Warwidow (0/1)"
putexcel A4 = "R2"
putexcel A5 = "Observations"
putexcel A6 = "Control mean"

sum `y' if d_warwidow == 0
putexcel B6 = `r(mean)'

reg `y' d_warwidow i.birth_year, vce(cluster district_no)
putexcel B2 =  matrix(_b[d_warwidow] \ _se[d_warwidow] \ e(r2) \ e(N))
reg `y' d_warwidow d_houseowner_1939 d_expellee d_SBZ siblings i.years_education i.birth_year, vce(cluster district_no)
putexcel C2 =  matrix(_b[d_warwidow] \ _se[d_warwidow] \ e(r2) \ e(N))
reg `y' d_warwidow d_houseowner_1939 d_expellee d_SBZ siblings i.years_education i.occ_cat10_1939 i.sector_cat6_1939 i.birth_year, vce(cluster district_no)
putexcel D2 =  matrix(_b[d_warwidow] \ _se[d_warwidow] \ e(r2) \ e(N))
teffects ipw (`y') (d_warwidow d_houseowner_1939 d_expellee d_SBZ siblings i.years_education i.occ_cat10_1939 i.sector_cat6_1939 i.birth_year), atet vce(cluster district_no)
putexcel E2 =  matrix(_b[ATET:r1vs0.d_warwidow] \ _se[ATET:r1vs0.d_warwidow] \ e(r2) \ e(N))
}


* Diagnostics
putexcel set "$widowsdir/results/tables/reg_`sample'.xlsx", modify sheet(diagnostics)
tebalance summarize
putexcel A1 = matrix(r(table)), names


********************************************************************************
*** b) Income and labor market outcomes conditional on market employment
***	   (Table 2, Panel C2; Table 3, Panel B.) 
********************************************************************************

*** Dependent variable: 
foreach t in 1950 1960 1971{
foreach y in 	income_midpoints_level ///
				d_selfemployed_`t' d_farmer_`t' d_civilservant_`t' d_whitecollar_`t' d_bluecollar_`t' {

* Define local for names of dependent variable and sheet
if "`y'" == "income_midpoints_level"{
local depvar `"Income interval midpoints in 1971 (level)"'
local sheetname  `"midinc1971level"'
}

if "`y'" == "d_selfemployed_`t'"{
local depvar `"Self employed `t' (0/1)"'
local sheetname  `"selfemp`t'"'
}

if "`y'" == "d_farmer_`t'"{
local depvar `"Farmer `t' (0/1)"'
local sheetname  `"farmer`t'"'
}

if "`y'" == "d_civilservant_`t'"{
local depvar `"Civil servant `t' (0/1)"'
local sheetname  `"civilserv`t'"'
}

if "`y'" == "d_whitecollar_`t'"{
local depvar `"White collar `t' (0/1)"'
local sheetname  `"whitecol`t'"'
}

if "`y'" == "d_bluecollar_`t'"{
local depvar `"Blue collar `t' (0/1)"'
local sheetname  `"bluecol`t'"'
}


putexcel set "$widowsdir/results/tables/reg_`sample'_condmarket.xlsx", modify sheet(`sheetname')
putexcel B1 = "Dep: `depvar'"
putexcel A2 = "Warwidow (0/1)"
putexcel A4 = "R2"
putexcel A5 = "Observations"
putexcel A6 = "Control mean"

sum `y' if d_warwidow == 0 & d_status_`t'_cat1 == 1 == 1
putexcel B6 = `r(mean)'

reg `y' d_warwidow i.birth_year if d_status_`t'_cat1 == 1, vce(cluster district_no)
putexcel B2 =  matrix(_b[d_warwidow] \ _se[d_warwidow] \ e(r2) \ e(N))
reg `y' d_warwidow d_houseowner_1939 d_expellee d_SBZ siblings i.years_education i.birth_year if d_status_`t'_cat1 == 1, vce(cluster district_no)
putexcel C2 =  matrix(_b[d_warwidow] \ _se[d_warwidow] \ e(r2) \ e(N))
reg `y' d_warwidow d_houseowner_1939 d_expellee d_SBZ siblings i.years_education i.occ_cat10_1939 i.sector_cat6_1939 i.birth_year if d_status_`t'_cat1 == 1, vce(cluster district_no)
putexcel D2 =  matrix(_b[d_warwidow] \ _se[d_warwidow] \ e(r2) \ e(N))
teffects ipw (`y') (d_warwidow d_houseowner_1939 d_expellee d_SBZ siblings i.years_education i.occ_cat10_1939 i.sector_cat6_1939 i.birth_year) if d_status_`t'_cat1 == 1, atet vce(cluster district_no)
putexcel E2 =  matrix(_b[ATET:r1vs0.d_warwidow] \ _se[ATET:r1vs0.d_warwidow] \ e(r2) \ e(N))
}
}


* Diagnostics
putexcel set "$widowsdir/results/tables/reg_`sample'_condmarket.xlsx", modify sheet(diagnostics)
tebalance summarize
putexcel A1 = matrix(r(table)), names

restore
}


********************************************************************************
*** Table C1: Heterogeneity in the impact of war widowhood on market employment
*** 		  in 1950, 1960, 1971 
********************************************************************************


********************************************************************************
*** Generate additional variables for sample split 
********************************************************************************

** With and without kids

gen d_kids = .
replace d_kids = 1 if (kids_1971 > 0 & kids_1971 != .)
replace d_kids = 0 if (kids_1971 == 0 & kids_1971 != .)

** Low/high education 
 
gen d_education_low = 0 if years_education != .
replace d_education_low = 1 if inrange(years_education, 8, 10)

gen d_education_high = 0 if years_education != .
replace d_education_high = 1 if inrange(years_education, 11, 17)


********************************************************************************
*** Regressions 
********************************************************************************


foreach sample in sample_baseline { 

preserve 

** Baseline sample

keep if `sample' == 1

** Outcomes: Market employment in 1950, 1960, 1971 

foreach y in 	d_status_1950_cat1 d_status_1960_cat1 d_status_1971_cat1 {
	
** Sample split: kids, education, occupational status 1939
			
foreach subsample in d_kids d_education_high d_status_1939_cat1 d_status_1939_cat2 d_status_1939_cat4 {

** Define locals for dependent variable

if "`y'" == "d_status_1950_cat1"{
local depvar `"Market employment 1950 (0/1)"'
local sheetname  `"marempl1950"'
}

if "`y'" == "d_status_1960_cat1"{
local depvar `"Market employment 1960 (0/1)"'
local sheetname  `"marempl1960"'
}

if "`y'" == "d_status_1971_cat1"{
local depvar `"Market employment 1971 (0/1)"'
local sheetname  `"marempl1971"'
}


** Define locals for split variable

if "`subsample'" == "d_kids"{
local hetvar `"Kids 1971 (0/1)"'
local sheetnamehet  `"kids"'
}

if "`subsample'" == "d_education_high"{
local hetvar `"Education > 10 yrs. (0/1)"'
local sheetnamehet  `"educhigh"'
}


if "`subsample'" == "d_status_1939_cat1"{
local hetvar `"Market empl. 1939 (0/1)"'
local sheetnamehet  `"market"'
}

if "`subsample'" == "d_status_1939_cat2"{
local hetvar `"Helping fam. 1939 (0/1)"'
local sheetnamehet  `"famwork"'
}

if "`subsample'" == "d_status_1939_cat4"{
local hetvar `"Out of labforce 1939 (0/1)"'
local sheetnamehet  `"outlf"'
}


putexcel set "$widowsdir/results/tables/reghet_`sample'.xlsx", modify sheet(`sheetname'_`sheetnamehet')
putexcel B1 = "Dep: `depvar'"
putexcel B2 = "OLS: `hetvar'==1"
putexcel C2 = "IPW: `hetvar'==1"
putexcel D2 = "OLS: `hetvar'==0"
putexcel E2 = "IPW: `hetvar'==0"
putexcel A3 = "Warwidow (0/1)"
putexcel A5 = "R2"
putexcel A6 = "Observations"
putexcel A7 = "Control mean"

sum `y' if d_warwidow == 0 & `subsample' == 1
putexcel B7 = `r(mean)'

sum `y' if d_warwidow == 0 & `subsample' == 0
putexcel D7 = `r(mean)'

reg `y' d_warwidow d_houseowner_1939 d_expellee d_SBZ siblings i.years_education i.occ_cat10_1939 i.sector_cat6_1939 i.birth_year if `subsample' == 1, vce(cluster district_no)
putexcel B3 =  matrix(_b[d_warwidow] \ _se[d_warwidow] \ e(r2) \ e(N))
teffects ipw (`y') (d_warwidow d_houseowner_1939 d_expellee d_SBZ siblings i.years_education i.occ_cat10_1939 i.sector_cat6_1939 i.birth_year) if `subsample' == 1, atet vce(cluster district_no)
putexcel C3 =  matrix(_b[ATET:r1vs0.d_warwidow] \ _se[ATET:r1vs0.d_warwidow] \ e(r2) \ e(N))
	
reg `y' d_warwidow d_houseowner_1939 d_expellee d_SBZ siblings i.years_education i.occ_cat10_1939 i.sector_cat6_1939 i.birth_year if `subsample' == 0, vce(cluster district_no)
putexcel D3 =  matrix(_b[d_warwidow] \ _se[d_warwidow] \ e(r2) \ e(N))
teffects ipw (`y') (d_warwidow d_houseowner_1939 d_expellee d_SBZ siblings i.years_education i.occ_cat10_1939 i.sector_cat6_1939 i.birth_year) if `subsample' == 0, atet vce(cluster district_no)
putexcel E3 =  matrix(_b[ATET:r1vs0.d_warwidow] \ _se[ATET:r1vs0.d_warwidow] \ e(r2) \ e(N))

	
}					
}
				
restore
				
}

** End of file
	